package vn.edu.fpt.xml.back.apis.news;

import org.apache.commons.lang3.StringUtils;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import vn.edu.fpt.xml.back.entities.ArticleEntity;
import vn.edu.fpt.xml.back.services.news.NewsProviderService;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by hiephn on 2014/05/02.
 */
@Service
@RequestMapping("/news/provider")
public class NewsProviderApi {

    @Resource(name = "newsProviderService")
    protected NewsProviderService newsProviderService;

    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
    public String defaultPage() {
        return "News Provider default page";
    }

    @ResponseBody
    @RequestMapping(value = "channel-list",
            method = RequestMethod.GET
    )
    public List<String> getChannelList() {
        return newsProviderService.getChannelList();
    }

    @ResponseBody
    @RequestMapping(value = "home-page-content",
            method = RequestMethod.GET
    )
    public Map<String, String> getHomePageContent() {
        return newsProviderService.generateHomePageContent();
    }

    @ResponseBody
    @RequestMapping(
            value = "article",
            method = RequestMethod.GET
    )
    public ArticleEntity getArticle(@RequestParam(value = "symbolicLink", required = true) String symbolicLink) {
        return newsProviderService.getArticleBySymbolicLink(symbolicLink);
    }

}
